package com.shiguo365.market.display.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.ImageLoader;
import com.shiguo365.market.R;
import com.shiguo365.market.bean.Product;

import java.util.List;

/**
 * Created by caomenglong on 16/7/11.
 */
public class OrderAdapter extends ArrayAdapter<Product> {
    private int resourceId;

    public OrderAdapter(Context context, int resource, List<Product> objects) {
        super(context, resource, objects);
        resourceId =resource;
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Product product=getItem(position);
        View view;
        ViewHolder viewHolder;

        if(convertView == null){

            view = LayoutInflater.from(getContext()).inflate(resourceId,null);
            viewHolder=new ViewHolder();
            viewHolder.productImage=(ImageView) view.findViewById(R.id.imageViewOrderImage);
            viewHolder.productName= (TextView) view.findViewById(R.id.textViewOrderName);
            viewHolder.productSpecName=(TextView) view.findViewById(R.id.textViewOrderSpecname);
            view.setTag(viewHolder);

        }else {

            view = convertView;
            viewHolder=(ViewHolder) view.getTag();
        }



        ImageLoader imageLoader = ImageLoader.getInstance();
        imageLoader.displayImage(product.getImgurl(), viewHolder.productImage);
        viewHolder.productName.setText(product.getName());
        viewHolder.productSpecName.setText(product.getSpecname());
        return view;
    }

    class ViewHolder{
        ImageView productImage;
        TextView productName;
        TextView productSpecName;
    }
}
